//
//  Pusher.m
//  CapPush
//
//  Created by 李加建 on 2022/6/15.
//

#import "Pusher.h"
#import <JPush/JPUSHService.h>
#import <UserNotifications/UserNotifications.h>

@interface Pusher ()
<JPUSHRegisterDelegate>
@end

@implementation Pusher

+ (void)registerForRemoteNotifications {
    [[UIApplication sharedApplication] registerForRemoteNotifications];
    JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
    entity.types = JPAuthorizationOptionAlert |JPAuthorizationOptionBadge| JPAuthorizationOptionSound|JPAuthorizationOptionProvidesAppNotificationSettings;
    [JPUSHService registerForRemoteNotificationConfig:entity delegate:nil];
    
    [JPUSHService setLogOFF];
}

+ (void)registerDeviceToken:(NSData *)deviceToken {
    [JPUSHService registerDeviceToken:deviceToken];
}

+ (void)setupWithOption:(nullable NSDictionary *)option appKey:(NSString *)appKey channel:(NSString *)channel apsForProduction:(BOOL)isProduction {
    [JPUSHService setupWithOption:option appKey:appKey channel:channel apsForProduction:isProduction];
}

+ (void)handleRemoteNotification:(NSDictionary *)remoteInfo {
    [JPUSHService handleRemoteNotification:remoteInfo];
}

+ (void)registrationIDComplete:(void(^)(NSString *registrationID))complete {
    [JPUSHService registrationIDCompletionHandler:^(int resCode, NSString *registrationID) {
        complete(registrationID);
    }];
}

#pragma mark - JPUSHRegisterDelegate
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
    
    completionHandler();
}

- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
    
    completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionSound);
}

- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(UNNotification *)notification {
    
}

- (void)jpushNotificationAuthorization:(JPAuthorizationStatus)status withInfo:(NSDictionary *)info {
    
}

@end
